package band.wukong.practice.javase.core.thread.Scheduling;

import java.io.IOException;

/**
 * Desc: 调整线程优先级
 * Author: sunjs
 * Date: 2009-11-5 14:02:59
 */
public class TestPriority extends Thread {
    private static StringBuffer log = new StringBuffer();
    private static int count = 0;

    public void run() {
        for (int a = 0; a < 20; a++) {
            log.append(Thread.currentThread().getName() + ":" + a + "  ");
            if (++count % 10 == 0)
                log.append("\n");
        }
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        TestPriority machine1 = new TestPriority();
        TestPriority machine2 = new TestPriority();

        machine1.setName("m1");
        machine2.setName("m2");

        Thread main = Thread.currentThread();
        System.out.println("main.getPriority() = " + main.getPriority());
        System.out.println("machine1.getPriority() = " + machine1.getPriority());
        System.out.println("machine2.getPriority() = " + machine2.getPriority());

        machine1.setPriority(Thread.MIN_PRIORITY);
        machine2.setPriority(Thread.MAX_PRIORITY);

        machine1.start();
        machine2.start();

        Thread.sleep(2000);

        System.out.println(log);
    }
}
